﻿@using Microsoft.AspNetCore.Components.Web;
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop;
@using ThingsGateway.Foundation
@using ThingsGateway.NewLife.Threading
@using ThingsGateway.Extension;
@using BootstrapBlazor.Components
@namespace ThingsGateway.Debug

<div class="w-100" style=@($"height:{HeightString}")>

    <Card HeaderText=@HeaderText class=@("w-100 h-100")>
    <HeaderTemplate>
        <div class="flex-fill">
        </div>

        @if (LogLevelChanged.HasDelegate)
        {
            <Select Value="@LogLevel" ValueChanged="LogLevelChanged" IsPopover></Select>
        }
        <Tooltip class=" col-auto" Title="@RazorLocalizer[Pause?"Play":"Pause"]" Placement="Placement.Bottom">

            <Button Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@(Pause?"fa fa-play":"fa fa-pause") OnClick="OnPause" />

        </Tooltip>

        <Tooltip class=" col-auto" Title="@RazorLocalizer["Export"]" Placement="Placement.Bottom">

            <Button IsAsync Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@("fa fa-sign-out") OnClick="HandleOnExportClick" />

        </Tooltip>

        <Tooltip class=" col-auto" Title="@RazorLocalizer["Delete"]" Placement="Placement.Bottom">

            <Button IsAsync Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@("far fa-trash-alt") OnClick="Delete" />

        </Tooltip>


    </HeaderTemplate>
    <BodyTemplate>
                <div style=@($"height:calc(100% - 50px);overflow-y:scroll;flex-fill;")>
            <Virtualize Items="CurrentMessages??new  List<LogMessage>()" Context="itemMessage" ItemSize="60" OverscanCount=2>
                <ItemContent>
                    @*       <Tooltip Placement="Placement.Bottom" Title=@itemMessage.Message.Substring(0, Math.Min(itemMessage.Message.Length, 500))> *@
                    <div class=@(itemMessage.Level<(byte)Microsoft.Extensions.Logging.LogLevel.Information?"":
                         itemMessage.Level>=(byte)Microsoft.Extensions.Logging.LogLevel.Warning? " red--text text-truncate":"green--text text-truncate")
                         title=@itemMessage.Message.Substring(0, Math.Min(itemMessage.Message.Length, 500))>

                        @itemMessage.Message.Substring(0, Math.Min(itemMessage.Message.Length, 150))

                    </div>
                    @* </Tooltip> *@
                </ItemContent>
            </Virtualize>
        </div>

    </BodyTemplate>
</Card>


</div>
